package cn.keniykey.mc.landterritory.vault;

import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.plugin.RegisteredServiceProvider;

import net.milkbowl.vault.economy.Economy;

public final class EconVault extends Econ{
	private final Economy vault;
	
	EconVault() {
		RegisteredServiceProvider<Economy> economy = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
		this.vault = economy.getProvider();
	}
	//
	@Override
	public boolean isEnable() {
		return (this.vault != null && this.vault.isEnabled());
	}
	@Override
	public boolean give(OfflinePlayer p, double price) {
		if (!this.isEnable()) return false;
		return this.vault.depositPlayer(p, price).transactionSuccess();
	}
	@Override
	public boolean take(OfflinePlayer p, double price) {
		if (!this.isEnable()) return false;
		return this.vault.withdrawPlayer(p, price).transactionSuccess();
	}
	@Override
	public double get(OfflinePlayer p) {
		if (!this.isEnable()) return 0d;
		return this.vault.getBalance(p);
	}
	@Override
	public boolean has(OfflinePlayer p,double price) {
		if (!this.isEnable()) return false;
		return this.vault.has(p, price);
	}
}